// 配置路由 这是路由文件
import Vue from 'vue'
import Router from 'vue-router'
// 这里规定从哪里提取跳转所需的页面
import Login from '../pages/Login'
import Layout from '../pages/Layout'
// 菜单选项
import Menu from '../pages/menu/Index'
import Add from '../pages/menu/Add'
import Edit from '../pages/menu/Edit'

// 角色管理
import Role from '../pages/role/Index'
import RoleAdd from '../pages/role/Add'
import RoleEdit from '../pages/role/Edit'

// 商品管理
import Categroy from '../pages/categroy/Index'
import CategroyAdd from '../pages/categroy/Add'
import CategroyEdit from '../pages/categroy/Edit'

// 引入Wangedit
import Wangedit from '../pages/Wangedit'

// 规格管理
import Specs from '../pages/specs/Index'

// 配置echarts
import Echarts from '../pages/gong/Echarts'
import Tiao from '../pages/gong/Tiao'
Vue.use(Router)

// goods
import Goods from '../pages/goods/Index'
import GoodsAdd from '../pages/goods/Add'
import GoodsEdit from '../pages/goods/Edit'

// 管理员页面
import Guan from '../pages/guan/Index'
import GuanAdd from '../pages/guan/Add'
import GuanEdit from '../pages/guan/Edit'

// 404
import NotFound from '../pages/notfound/NotFound'

// 这里指定了跳转路由你所指定的路径
const routes =[
        {
            path:'/layout',
            name:'Layout',
            // 这里是不加引号的!
            component:Layout,
            // 重定向
            // redirect:'/Wangedit',
            children:[
                {
                    // 既然是二级路由，那还是在一级路由基础上写
                    path:'/menu',
                    component:Menu
                },
                {
                    path:'/layout/add',
                    component:Add
                },
                {
                    path:'/layout/edit/:id',
                    component:Edit
                },
                {
                    path:'/role',
                    component:Role
                },
                {
                    path:'/role/add',
                    component:RoleAdd
                },
                {
                    path:'/role/edit/:id',
                    component:RoleEdit
                },
                {
                    path:'/category',
                    component:Categroy
                },
                {
                    path:'/categroy/Add',
                    component:CategroyAdd
                },
                {
                    path:'/categroy/edit/:id',
                    component:CategroyEdit
                },
                {
                    path:'/Wangedit',
                    component:Wangedit
                },
                {
                    path:'/specs',
                    component:Specs
                },
                {
                    path:'/echarts',
                    component:Echarts
                },
                {
                    path:'/tiao',
                    component:Tiao
                },
                {
                    path:'/goods',
                    component:Goods
                },
                {
                    path:'/goods/add',
                    component:GoodsAdd
                },
                {
                    path:'/goods/:id',
                    component:GoodsEdit
                },
                {
                    path:'/admin',
                    component:Guan
                },
                {
                    path:'/guan/add',
                    component:GuanAdd
                },
                {
                    // 这里叫uid，接收的地方就叫uid
                    path:'/guan/:uid',
                    component:GuanEdit,
                    //1:表示id？？
                    props:true
                },
                {
                    path:'*',
                    component:NotFound,
                }
            ]
        },
        {
            path:'/login',
            name:"Login",
            component:Login
        }
]

const router  =  new Router({
    routes
})

// 路由导航守卫
router.beforeEach(function(to,from,next){
    if(to.path!=='/login'){
        // 读取页面登陆信息
        const userInfo = sessionStorage.getItem('userinfo')
        // 如果用户名和密码不正确
        if(!userInfo){
            // 如果没有登陆  重定向
            return next('/login')
        }
    }
    // 正确就执行下一步
    next()
})

// 导出路由错误、图片文件夹名字错误、less的文件件没有放内容 三处错误
export default router
